home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
038a
/
bas_int1.zip
/
ATTRIB.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-03-02
|
9KB
|
130 lines
'===========================================================================
' Date : 27-Feb-91 1:06
' From : Frank Rakoczy
'Subject : ATTRIBUTES
'
'You can use dosfn 43h subfunction 0 to read file attributes or sub
'function 1 to set or clear file attributes.
'===========================================================================
DECLARE FUNCTION FileAttrib% (Action AS INTEGER, Attrib AS INTEGER,_
PathName AS STRING)
' $INCLUDE: 'qb.bi' 'needed for definition or RegTypeX and
' DECLARE statement for interruptX
'
'Define legal actions for function FileAttrib
CONST GetAttrib% = 0, SetAttrib% = 1
'Define bit flags for file attributes. Note that dosfn 43h will upchuck
'if you try set the volume label bit (bit 3) or the directory bit
'(bit 4) of an existing file. These bits have not been defined below.
'
CONST Areadonly% = &H1, Ahidden = &H2, Asystem = &H4, Aarchive = &H20
'-----------------------------------------------------------------------
'--- A small piece of test code
DIM Attrib AS INTEGER 'set up a couple of variables
PathName$ = "Phantom.Fil"
OPEN PathName$ FOR OUTPUT AS #1 'open a file and throw some
PRINT #1, "Now You See Me -- Now You Don't" 'trash in it
CLOSE #1 'close it
CLS
PRINT "Now You See Me" 'see if it exists
FILES "*.fil"
PRINT
'mark file as hidden -- call function to get current file attributes
Attrib = FileAttrib(GetAttrib, 0, PathName$)
'call again to set attributes to current + hidden
Attrib = FileAttrib(SetAttrib, Attrib OR Ahidden, PathName$)
'
'if you wish you can check for errors after each call
'IF Attrib < 0 THEN GOSUB ERRRCHK
'
PRINT "The Phantom File has now gone South"
ON ERROR GOTO NEXT1 'The call to Files will generate an error here
FILES "*.fil" 'because the file has been marked hidden in the
PRINT 'previous call to FileAttrib%()
NEXT1:
RESUME NEXT
'turn off hidden bit -- get the file' current attributes
Attrib = FileAttrib(GetAttrib, 0, PathName$)
'call FileAttrib to turn off hidden bit
Attrib = FileAttrib(SetAttrib, Attrib - Ahidden, PathName$)
PRINT "The Phantom has returned"
FILES "*.fil"
'
'ERRCHK:
'Attrib = Attrib AND &H7F 'convert return value to error code
' .
' . and take any necessary corrective action here
' .
'RETURN
'
'END OF TEST CODE -- TRASH THIS WHEN YOU UNDERSTAND THE FUNCTION
'-------------------------------------------------------------------------
FUNCTION FileAttrib% (Action AS INTEGER, Attrib AS INTEGER,_
PathName AS STRING)
DIM r AS RegTypeX
'The dosfn expects the address of an ASCIIZ pathname and this is not the
'string format used by basic. So copy the PathName argument to a temporary
'string and append chr$(0) to the original PathName.
Temp$ = PathName$ + CHR$(0)
r.ax = &H4300 + Action 'AH gets 43h and AL gets action (set or get)
r.cx = Attrib 'load requested attribute into cx
'dosfn 43h expects ds:dx to point to the asciiz path name of the file.
'NOTE: The coding below takes into account the possibility of the temporary
'path name string being in a far data segment. As far a I know, Basic's
'internal memory management routines do everything possible to keep this
'from happening. You should be able to implement this code using call
'interrupt and load r.dx with sadd(temp$). Then you won't have to worry
'about messing with the segment registers.
r.ds = VARSEG(Temp$) 'load DS with segment address
r.dx = SADD(Temp$)'load DX with offset address
r.es = -1 'use current value of es
CALL INTERRUPTX(&H21, r, r) 'call dos to perform requested operation
'Dos will return the carry flag clear if the call was successful. If
'there was an error the cflag will be set. You can check this condition
'and adjust the return value accordingly. For the purposes of this demo
'I will use the following method:
'If cflag = 0 then return the attribute. If cflag is non zero then r.ax
'contains a dos error code. Because the value of the err code or the
'attribute will always be a positive value we can get away with the
'following.
IF r.flags AND &H1 THEN 'if carry flag is set then an error occurred
FileAttrib% = r.ax AND &H80
'return the error code forced to a negative value. The calling module can
'check the return value for a < 0 condition and detect any error. To
'change the return value to the proper error code the calling module can
'AND the return value with &H7F and the value will be the error code
'returned by DOS. The calling module can then take any required action
ELSE 'no error so return attribute
FileAttrib% = r.cx
END IF
END FUNCTION